package mblog.web.interceptor.bean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

import mblog.web.interceptor.NavDataInterceptor;
import mblog.web.interceptor.NavDataInterceptor.ProductNav;
import mblog.web.interceptor.NavDataInterceptor.ZhiboNav;

public class NavDataMap extends ConcurrentHashMap<Object, Object> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7405677781517580954L;
	public static final NavDataMap navDatas = new NavDataMap(400, 0.9f, 32);

	public NavDataMap(){
		
	}
	
	public NavDataMap(int initialCapacity, float loadFactor, int concurrencyLevel) {
		super(initialCapacity, loadFactor, concurrencyLevel);
	}

	public ZhiboNav getZhiboData(String sessionId) {
		@SuppressWarnings("unchecked")
		HashMap<String, Object> infoMap = (HashMap<String, Object>) navDatas.get(sessionId);

		if (infoMap != null) {
			return (ZhiboNav) infoMap.get(NavDataInterceptor.navZhiboDataToken);
		}

		return null;
	}

	@SuppressWarnings("unchecked")
	public List<ProductNav> getNavNews(String sessionId) {
		HashMap<String, Object> infoMap = (HashMap<String, Object>) navDatas.get(sessionId);

		if (infoMap != null) {
			return (List<ProductNav>) infoMap.get(NavDataInterceptor.navNewsDataToken);
		}

		return new ArrayList<ProductNav>();
	}

	@SuppressWarnings("unchecked")
	public List<ProductNav> getNavProduct(String sessionId) {
		HashMap<String, Object> infoMap = (HashMap<String, Object>) navDatas.get(sessionId);

		if (infoMap != null) {
			return (List<ProductNav>) infoMap.get(NavDataInterceptor.navProDataToken);
		}

		return new ArrayList<ProductNav>();
	}
}